package com.woniuxy.service.impl;

import com.woniuxy.mapper.GoodsMapper;
import com.woniuxy.service.GoodsService;
import com.work.framework.pojo.*;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author fengyao
 * @version 1.0
 * @date 2019/9/19 0019 上午 11:36
 */
@Service
//@EnableCaching
public class GoodsServiceImpl implements GoodsService {

    @Resource
    GoodsMapper goodsMapper;

    @Override
//    @Cacheable(value="goods",keyGenerator = "myKeyGenerator")
    public GoodsAuctionDTO selectGoodsAndAuctionByGid(Integer gid) {
        GoodsAuctionDTO goodsAuctionDTO = goodsMapper.selectGoodsAuctionDTO(gid);
        return goodsAuctionDTO;
    }

    @Override
//    @Cacheable(value="goods",keyGenerator = "myKeyGenerator")
    public Auction selectAuctionByGid(Integer aid) {
        Auction auction = goodsMapper.selectGoodsAuctionByGid(aid);
        return auction;
    }

    /**
     *
     * @param gid 商品id
     * @return
     */
    @Override
//    @Cacheable(value="goods",keyGenerator = "myKeyGenerator")
    public List<User> selectUsersByGid(Integer gid) {
        List<User> users = goodsMapper.selectUsersByGid(gid);
        return users;
    }

    @Override
//    @Cacheable(value="goods",keyGenerator = "myKeyGenerator")
    public List<String> selectOtherPictures(Integer gid) {
        List<String> strings = goodsMapper.selectOtherPicture(gid);
        return strings;
    }

    @Override
//    @Cacheable(value="goods",keyGenerator = "myKeyGenerator")
    public Enshrine selectEnshrine(Integer uid, Integer gid) {
        Enshrine enshrine=goodsMapper.findEnshrineByUidAndGid(uid,gid);
        return enshrine;
    }

    @Override
//    @CachePut(value="goods",keyGenerator = "myKeyGenerator")
    public void insertEnshrine(Integer uid, Integer gid) {
        goodsMapper.insertEnshrine(uid,gid);
    }

    @Override
//    @CacheEvict(value="goods",keyGenerator = "myKeyGenerator")
    public void updateEnshrine(Integer uid, Integer gid) {
        goodsMapper.updateEnshrine(uid, gid);
    }

    @Override
//    @CacheEvict(value="goods",keyGenerator = "myKeyGenerator")
    public void updateGoodsEnshrineCount(Integer count, Integer gid) {
        goodsMapper.updateGoodsEnshrineCount(count,gid);
    }

    @Override
//    @CacheEvict(value="goods",keyGenerator = "myKeyGenerator")
    public void noEnshrine(Integer uid, Integer gid) {
        goodsMapper.noEnshrine(uid,gid);
    }

    @Override
//    @CacheEvict(value="goods",keyGenerator = "myKeyGenerator")
    public void updateAuctionValid(Integer gid) {
        goodsMapper.updateAuctionValid(gid);
    }

    @Override
    public void updateAuctionStatus(Integer aid, Integer status) {
        goodsMapper.updateAuctionStatus(aid,status);
    }

    @Override
    public void insertGoods(Goods goods) {
        goodsMapper.insertGoods(goods);
    }

    @Override
    public void insertAuction(Auction auction) {
        goodsMapper.insertAuction(auction);
    }

    @Override
    public void insertPicture(Picture picture) {
        goodsMapper.insertPicture(picture);
    }

    @Override
    public Integer selectUidByAid(Integer aid) {

        Integer integer = goodsMapper.selectUidByAid(aid);
        return integer;
    }

    @Override
    public GoodsAuctionDTO selectGoodsAuctionDTOByAid(Integer aid) {
        GoodsAuctionDTO goodsAuctionDTO = goodsMapper.selectGoodsAuctionDTOByAid(aid);
        return goodsAuctionDTO;
    }
}
